package com.orange.off.cloud.cloudoff.adapters;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.orange.off.cloud.cloudoff.R;
import com.orange.off.cloud.cloudoff.activity.IntermediaryActivity;
import com.orange.off.cloud.cloudoff.base.ListBaseAdapter;
import com.orange.off.cloud.cloudoff.base.SuperViewHolder;
import com.orange.off.cloud.cloudoff.model.Client_Recording_ListBean;
import com.orange.off.cloud.cloudoff.utils.PhoneUtils;

/**
 * 我的客户推荐记录
 *
 * @author smile
 */
public class Client_Recording_ListAdapter extends ListBaseAdapter<Client_Recording_ListBean> {

    public Client_Recording_ListAdapter(Context context) {
        super(context);

    }

    @Override
    public int getLayoutId() {
        return R.layout.client_recording_items;
    }

    @Override
    public void onBindItemHolder(SuperViewHolder holder, int position) {
        ViewHolder viewHodler = new ViewHolder();
        final Client_Recording_ListBean item = mDataList.get(position);
        viewHodler.client_recording_items_avatar = holder.getView(R.id.client_recording_items_avatar);
        viewHodler.client_recording_items_name = holder.getView(R.id.client_recording_items_name);
        viewHodler.client_recording_items_time = holder.getView(R.id.client_recording_items_time);
        viewHodler.client_recording_items_project = holder.getView(R.id.client_recording_items_project);
        viewHodler.client_recording_items_not_send = holder.getView(R.id.client_recording_items_not_send);
        viewHodler.client_recording_items_send = holder.getView(R.id.client_recording_items_send);
        viewHodler.client_recording_items_to_visit_money = holder.getView(R.id.client_recording_items_to_visit_money);
        viewHodler.client_recording_items_to_visit_img = holder.getView(R.id.client_recording_items_to_visit_img);
        viewHodler.client_recording_items_identify_chips_money = holder.getView(R.id.client_recording_items_identify_chips_money);
        viewHodler.client_recording_items_identify_chips_img = holder.getView(R.id.client_recording_items_identify_chips_img);
        viewHodler.client_recording_items_subscription_money = holder.getView(R.id.client_recording_items_subscription_money);
        viewHodler.client_recording_items_subscription_img = holder.getView(R.id.client_recording_items_subscription_img);
        viewHodler.client_recording_items_signed_money = holder.getView(R.id.client_recording_items_signed_money);
        viewHodler.client_recording_items_signed_img = holder.getView(R.id.client_recording_items_signed_img);
        viewHodler.client_recording_items_to_visit_linear = holder.getView(R.id.client_recording_items_to_visit_linear);
        viewHodler.client_recording_items_identify_chips_linear = holder.getView(R.id.client_recording_items_identify_chips_linear);
        viewHodler.client_recording_items_subscription_linear = holder.getView(R.id.client_recording_items_subscription_linear);
        viewHodler.client_recording_items_signed_linear = holder.getView(R.id.client_recording_items_signed_linear);

        viewHodler.client_recording_items_call_linear = holder.getView(R.id.client_recording_items_call_linear);
        viewHodler.client_recording_items_recommend_linear = holder.getView(R.id.client_recording_items_recommend_linear);
        viewHodler.client_recording_items_name.setText(item.name);
        viewHodler.client_recording_items_time.setText(item.addtime);
        viewHodler.client_recording_items_project.setText(item.xname);
        viewHodler.client_recording_items_not_send.setText("应发：" + item.ym);
        viewHodler.client_recording_items_send.setText("已发：" + item.hm);
        String sex = item.sex;
        switch (sex) {
            case "男":
                viewHodler.client_recording_items_avatar.setBackgroundDrawable(mContext.getResources().getDrawable(R.drawable.avatar_man));
                break;
            case "女":
                viewHodler.client_recording_items_avatar.setBackgroundDrawable(mContext.getResources().getDrawable(R.drawable.avatar_woman));
                break;
            default:
                viewHodler.client_recording_items_avatar.setBackgroundDrawable(mContext.getResources().getDrawable(R.drawable.avatar_no_sex));
                break;
        }
        String lf = item.lf;//1:未通过（灰）2：结算未发（红）3：已结算（绿）
        switch (lf) {//来访
            case "1":
                viewHodler.client_recording_items_to_visit_img.setBackgroundDrawable(mContext.getResources().getDrawable(R.drawable.login_check_false));
                viewHodler.client_recording_items_to_visit_linear.setBackgroundDrawable(mContext.getResources().getDrawable(R.drawable.edit_bg));
                viewHodler.client_recording_items_to_visit_money.setTextColor(mContext.getResources().getColor(R.color.text_color));
                break;
            case "2":
                viewHodler.client_recording_items_to_visit_img.setBackgroundDrawable(mContext.getResources().getDrawable(R.drawable.client_correct_red));
                viewHodler.client_recording_items_to_visit_linear.setBackgroundDrawable(mContext.getResources().getDrawable(R.drawable.client_frame_red));
                viewHodler.client_recording_items_to_visit_money.setTextColor(mContext.getResources().getColor(R.color.red));
                break;
            case "3":
                viewHodler.client_recording_items_to_visit_img.setBackgroundDrawable(mContext.getResources().getDrawable(R.drawable.client_correct_green));
                viewHodler.client_recording_items_to_visit_linear.setBackgroundDrawable(mContext.getResources().getDrawable(R.drawable.client_frame_green));
                viewHodler.client_recording_items_to_visit_money.setTextColor(mContext.getResources().getColor(R.color.green));
                break;
        }
        viewHodler.client_recording_items_to_visit_money.setText(item.lf_cash);

        String rc = item.rc;//认筹--1:未通过（灰）2：结算未发（红）3：已结算（绿）
        switch (rc) {
            case "1":
                viewHodler.client_recording_items_identify_chips_img.setBackgroundDrawable(mContext.getResources().getDrawable(R.drawable.login_check_false));
                viewHodler.client_recording_items_identify_chips_linear.setBackgroundDrawable(mContext.getResources().getDrawable(R.drawable.edit_bg));
                viewHodler.client_recording_items_identify_chips_money.setTextColor(mContext.getResources().getColor(R.color.text_color));
                break;
            case "2":
                viewHodler.client_recording_items_identify_chips_img.setBackgroundDrawable(mContext.getResources().getDrawable(R.drawable.client_correct_red));
                viewHodler.client_recording_items_identify_chips_linear.setBackgroundDrawable(mContext.getResources().getDrawable(R.drawable.client_frame_red));
                viewHodler.client_recording_items_identify_chips_money.setTextColor(mContext.getResources().getColor(R.color.red));
                break;
            case "3":
                viewHodler.client_recording_items_identify_chips_img.setBackgroundDrawable(mContext.getResources().getDrawable(R.drawable.client_correct_green));
                viewHodler.client_recording_items_identify_chips_linear.setBackgroundDrawable(mContext.getResources().getDrawable(R.drawable.client_frame_green));
                viewHodler.client_recording_items_identify_chips_money.setTextColor(mContext.getResources().getColor(R.color.green));
                break;
        }
        viewHodler.client_recording_items_identify_chips_money.setText(item.rc_cash);

        String rg = item.rg;//认购--1:未通过（灰）2：结算未发（红）3：已结算（绿）
        switch (rg) {
            case "1":
                viewHodler.client_recording_items_subscription_img.setBackgroundDrawable(mContext.getResources().getDrawable(R.drawable.login_check_false));
                viewHodler.client_recording_items_subscription_linear.setBackgroundDrawable(mContext.getResources().getDrawable(R.drawable.edit_bg));
                viewHodler.client_recording_items_subscription_money.setTextColor(mContext.getResources().getColor(R.color.text_color));
                break;
            case "2":
                viewHodler.client_recording_items_subscription_img.setBackgroundDrawable(mContext.getResources().getDrawable(R.drawable.client_correct_red));
                viewHodler.client_recording_items_subscription_linear.setBackgroundDrawable(mContext.getResources().getDrawable(R.drawable.client_frame_red));
                viewHodler.client_recording_items_subscription_money.setTextColor(mContext.getResources().getColor(R.color.red));
                break;
            case "3":
                viewHodler.client_recording_items_subscription_img.setBackgroundDrawable(mContext.getResources().getDrawable(R.drawable.client_correct_green));
                viewHodler.client_recording_items_subscription_linear.setBackgroundDrawable(mContext.getResources().getDrawable(R.drawable.client_frame_green));
                viewHodler.client_recording_items_subscription_money.setTextColor(mContext.getResources().getColor(R.color.green));
                break;
        }
        viewHodler.client_recording_items_subscription_money.setText(item.rg_cash);
        String qy = item.qy;//签约--1:未通过（灰）2：结算未发（红）3：已结算（绿）
        switch (qy) {
            case "1":
                viewHodler.client_recording_items_signed_img.setBackgroundDrawable(mContext.getResources().getDrawable(R.drawable.login_check_false));
                viewHodler.client_recording_items_signed_linear.setBackgroundDrawable(mContext.getResources().getDrawable(R.drawable.edit_bg));
                viewHodler.client_recording_items_signed_money.setTextColor(mContext.getResources().getColor(R.color.text_color));
                break;
            case "2":
                viewHodler.client_recording_items_signed_img.setBackgroundDrawable(mContext.getResources().getDrawable(R.drawable.client_correct_red));
                viewHodler.client_recording_items_signed_linear.setBackgroundDrawable(mContext.getResources().getDrawable(R.drawable.client_frame_red));
                viewHodler.client_recording_items_signed_money.setTextColor(mContext.getResources().getColor(R.color.red));
                break;
            case "3":
                viewHodler.client_recording_items_signed_img.setBackgroundDrawable(mContext.getResources().getDrawable(R.drawable.client_correct_green));
                viewHodler.client_recording_items_signed_linear.setBackgroundDrawable(mContext.getResources().getDrawable(R.drawable.client_frame_green));
                viewHodler.client_recording_items_signed_money.setTextColor(mContext.getResources().getColor(R.color.green));
                break;
        }
        viewHodler.client_recording_items_signed_money.setText(item.qy_cash);
        viewHodler.client_recording_items_call_linear.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                PhoneUtils.call(mContext, item.phone);
            }
        });
        viewHodler.client_recording_items_recommend_linear.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(mContext, IntermediaryActivity.class);
                intent.putExtra("type", IntermediaryActivity.CLIENT_ADD);
                Bundle bundle = new Bundle();
                bundle.putString("project_name", item.xname);//楼盘名字
                bundle.putString("name", item.name);//客户姓名
                bundle.putString("id", item.xid);//楼盘id
                bundle.putString("sex", item.sex);//客户性别
                bundle.putString("phone", item.phone);//客户电话
                bundle.putString("oplist", item.oplist);//客户电话
                intent.putExtra("bundle", bundle);
                mContext.startActivity(intent);
            }
        });
    }

    class ViewHolder {
        ImageView client_recording_items_avatar;//性别头像
        TextView client_recording_items_name;//姓名
        TextView client_recording_items_time;//创建日期
        TextView client_recording_items_project;//项目名称
        TextView client_recording_items_not_send;//应发
        TextView client_recording_items_send;//已发
        LinearLayout client_recording_items_to_visit_linear;//到访
        TextView client_recording_items_to_visit_money;//到访应发钱数
        ImageView client_recording_items_to_visit_img;//到访状态img
        LinearLayout client_recording_items_identify_chips_linear;//认筹
        TextView client_recording_items_identify_chips_money;//认筹应发钱数
        ImageView client_recording_items_identify_chips_img;//认筹状态img
        LinearLayout client_recording_items_subscription_linear;//认购
        TextView client_recording_items_subscription_money;//认购应发钱数
        ImageView client_recording_items_subscription_img;//认购状态img
        LinearLayout client_recording_items_signed_linear;//签约
        TextView client_recording_items_signed_money;//签约应发钱数
        ImageView client_recording_items_signed_img;//签约状态img
        LinearLayout client_recording_items_call_linear;//打电话
        LinearLayout client_recording_items_recommend_linear;//推荐
    }
}
